//
//  WGuoListViewController.swift
//  iiatn
//
//  Created by mine on 18/5/11.
//  Copyright © 2018年 mnine. All rights reserved.
//

import UIKit

class WGuoListViewController: UIViewController {

    // 滚动视图
    @IBOutlet var scroll: UIScrollView!
    
    @IBOutlet var l1: UILabel!
    
    @IBOutlet var l2: UILabel!
    
    @IBOutlet var l3: UILabel!
    
    @IBOutlet var l4: UILabel!
    
    @IBOutlet var l5: UILabel!
    
    @IBOutlet var l6: UILabel!
    
    var ls = [UILabel]()
    
    let zhou = ["亚洲","欧洲","大洋洲","北美洲","南美洲"]
    
    let g1 = ["日本","印度","马来西亚","新加坡","巴基斯坦","印度尼西亚","泰国","孟加拉","韩国","蒙古国","朝鲜","阿富汗","阿拉伯联合酋长国","阿曼","阿塞拜疆","巴林","东帝汶","菲律宾","格鲁吉亚","哈萨克斯坦","吉尔吉斯斯坦","柬埔寨王国","卡塔尔","科威特","老挝","黎巴嫩","马尔代夫","缅甸","尼泊尔","沙特阿拉伯","斯里兰卡","塔吉克斯坦","土耳其","土库曼斯坦","文莱","乌兹别克斯坦","叙利亚","亚美尼亚","也门","伊拉克","伊朗","以色列","约旦","越南","不丹"]
    
    let g2 = ["英国","德国","俄罗斯","西班牙","法国","意大利","葡萄牙","希腊","爱尔兰","荷兰","比利时","卢森堡","波兰","阿尔巴尼亚","爱沙尼亚","奥地利","白俄罗斯","保加利亚","冰岛","波黑","丹麦","芬兰","捷克","克罗地亚","拉脱维亚","立陶宛","罗马尼亚","马耳他","马其顿","摩尔多瓦","挪威","瑞典","瑞士","塞浦路斯","斯洛伐克","斯洛文尼亚","乌克兰","匈牙利","塞尔维亚"]
    
    let g3 = ["尼日利亚","埃及","南非","阿尔及利亚","埃塞俄比亚","安哥拉","贝宁","博兹瓦纳","布基纳法索","布隆迪","赤道几内亚","多哥","厄立特里亚","佛得角","刚果（布）","刚果（金）","吉布提","几内亚","几内亚比绍","加纳","加蓬","津巴布韦","喀麦隆","科摩罗","科特迪瓦","肯尼亚","莱索托","利比里亚","利比亚","卢旺达","马达加斯加","马拉维","马里","毛里求斯","毛里塔尼亚","摩洛哥","莫桑比克","纳米比亚","南苏丹","尼日尔","塞拉利昂","塞内加尔","塞舌尔","苏丹","索马里","坦桑尼亚","突尼斯","乌干达","赞比亚","乍得","中非"]
    
    let g4 = ["澳大利亚","新西兰","巴布亚新几内亚","斐济","密克罗尼西亚","萨摩亚","瓦努阿图","汤加"]
    
    let g5 = ["美国","加拿大","墨西哥","安提瓜和巴布达","巴巴多斯","巴哈马","巴拿马","多米尼克国","哥斯达黎加","格林纳达","古巴","洪都拉斯","特立尼达和多巴哥","牙买加"]
    
    let g6 = ["巴西","阿根廷","秘鲁","智利","巴拉圭","玻利维亚","厄瓜多尔","哥伦比亚","圭亚那","苏里南","委内瑞拉","乌拉圭"]
    
    var gs = [Array<Any>]()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setdata()
        setstyle()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    func setdata(){
        ls.append(l1)
        ls.append(l2)
        ls.append(l3)
        ls.append(l4)
        ls.append(l5)
        ls.append(l6)
        gs.append(g1)
        gs.append(g2)
        gs.append(g3)
        gs.append(g4)
        gs.append(g5)
        gs.append(g6)
    }
    func setstyle(){
        scroll.width = SCREENW
        scroll.height = SCREENH - 20

        var y_zero = 8
        var li = 0
        let width = 66
        let loop = Int((Int(SCREENW) - 68)/width)
        
        for l in ls{
            l.y = CGFloat(y_zero)
            var gi = 0
            for g in gs[li] {
                let btn = setupBtn(title: g as! String)
                btn.x = CGFloat(70 + gi%loop*width)
                btn.y = CGFloat(y_zero + Int(gi/loop)*35)
                btn.addTarget(self, action: #selector(dosearch), for: .touchUpInside)
                scroll.addSubview(btn)
                gi = gi+1
            }
            y_zero = y_zero + Int(gi/loop)*35 + 30 + 18
            li = li + 1
        }
        
        scroll.contentSize = CGSize(width: SCREENW, height: l6.frame.maxY+110)
    }
    
    func setupBtn(title: String) -> UIButton{
        let btn = UIButton()
        btn.backgroundColor = WColor(r: 255, g: 255, b: 255, a: 0.85)
        btn.width = 62
        btn.height = 30
        btn.setTitle(title, for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        btn.setTitleColor(WColor(r: 0, g: 0, b: 0, a: 0.85), for: .normal)
        btn.setTitleColor(WColor(r: 255, g: 255, b: 255, a: 0.5), for: .highlighted)
        btn.setTitleColor(WColor(r: 255, g: 255, b: 255, a: 0.5), for: .selected)
        btn.layer.borderWidth = 0.4
        btn.layer.borderColor = UIColor.gray.cgColor
        btn.layer.cornerRadius = btn.height * 0.1
        btn.layer.masksToBounds = true
        btn.layer.rasterizationScale = UIScreen.main.scale
        return btn
    }

    func dosearch(button: UIButton){
        let key = button.title(for: .normal)
        print("\(key!)")
        toSearch(key: key!)
    }
    
    func toSearch(key: String){
        let detailVC = WSearchProViewController()
        detailVC.title = key
        detailVC.key = key
        navigationController?.pushViewController(detailVC, animated: true)
    }
}
